#coding=utf-8
import threading,time,common;
from core import core;
times = 1;#循环次数,请大于项目里最大的运行次数，因为项目失败的时候次数不会-1
#唯一识别code,关键词，信息流，翻页数，运行次数
list = [
    ['jc001',['天邪鬼赤'],'',1,1]
    # ['zjqjx','猪兼强驾校','猪兼强驾校怎么样,有没有人去过的呀? - 知乎',2,40],
    #['zyjy','卓越教育','卓越教育好吗?_百度知道',2,40],
    ]

lastIP = '';
def run(keyword,clickWord,pages,code):
    m  = core(keyword=keyword,clickWord = clickWord,pages = pages,success = 1,code=code)
    m.setCfg(find_all=1,event=-1,click=-1)
    return m.loop()
def main():
    global lastIP;
    appTimes = 0;
    result_log= {};
    
    while(times>appTimes):
        try:
            ip = common.get_out_ip();
        except:
            #获取ip失败则返回上一个ip
            ip = lastIP;
        if(ip!=lastIP):
            lastIP = ip
        else:
            print('ip没有变化，10s后重试');
            time.sleep(10)
            main()  
        appTimes = appTimes+1
        print('>>>第'+str(appTimes)+'次循环');
        for i in range(len(list)):
            if(list[i][4]>0):
                if result_log.get(i)== None:result_log[i] = 0;
                result = run(list[i][1],list[i][2],list[i][3],list[i][0])
                result_log[i] = result_log[i]+result;
                if(result==1):
                    list[i][4] = list[i][4]-1
                print('>>剩余次数：'+str(list[i][4])+'次');
                print('>>成功次数：'+str(result_log[i])+'次');
                print('################################');
                time.sleep(15);
   
if __name__ == '__main__':
    main()


   
